<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>发布商机</title>
    <link rel="stylesheet" href="css/ydui.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="iconfont/iconfont.css">
    <script src="js/ydui.flexible.js"></script>
</head>

<body>
    <div class="g-view releasePage" id="releasePage">
        <div class="business-type release-list">
            <div class="m-celltitle">
                <span>*</span>商机类型</div>
            <div class="m-cell">
                <div class="cell-item">
                    <label class="cell-right cell-arrow">
                        <select id="typeId" class="cell-select">
                            <option value="0">请选择商机类型</option>
                            <option v-for="(item, index) in goods_arry" :key="index" :value="item.id">{{item.name}}</option>
                        </select>
                    </label>
                </div>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>商机标题：</div>
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-right">
                        <textarea id="titleId" class="cell-textarea" placeholder="请输入商机标题"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>联系人：</div>
            <div class="cell-item">
                <div class="cell-right">
                    <input id="nameId" type="text" class="cell-input" placeholder="请输入联系人" autocomplete="off" />
                </div>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>联系手机：</div>
            <div class="cell-item">
                <div class="cell-right">
                    <input id="phoneId" type="number" pattern="[0-9]*" class="cell-input" placeholder="请输入手机号" autocomplete="off" />
                </div>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>收货地址</div>
            <div class="cell-item address">
                <select @change="city" name="" id="provinceId">
                    <option value="0">请选择省</option>
                    <option v-for="(item, index) in province_arry" :key="index" :value="item.id">{{item.name}}</option>
                </select>
                <select @change="area" name="" id="cityId">
                    <option value="0">请选择市</option>
                    <option v-for="(item, index) in city_arry" :key="index" :value="item.id">{{item.name}}</option>
                </select>
                <select name="" id="areaId">
                    <option value="0">请选择区</option>
                    <option v-for="(item, index) in area_arry" :key="index" :value="item.id">{{item.name}}</option>
                </select>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>采购量</div>
            <div class="cell-item">
                <div class="cell-right">
                    <input id="numId" class="cell-input" placeholder="请输入您的采购量" />
                </div>
            </div>
        </div>
        <div class="release-list">
            <div class="m-celltitle">
                <span>*</span>商机描述</div>
            <div class="m-cell">
                <div class="cell-item">
                    <div class="cell-right">
                        <textarea id="describeId" class="cell-textarea" placeholder="请输入您的商机描述"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <button @click="releaseSubmit" class="btn-block btn-primary">确认发布</button>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="index.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="release.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="vip.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/ydui.flexible.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/ydui.js"></script>
    <script src="js/nuoxia.js"></script>
    <script src="js/city.js"></script>
    <script>
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var releasePage = new Vue({
                el: "#releasePage",
                data: {
                    province_arry: [],
                    city_arry: [],
                    area_arry: [],
                    goods_arry: []
                },
                filters: {

                },
                mounted: function () {
                    this.province();
                    this.businessType();
                },
                methods: {
                    province: function () {
                        var _this = this;
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/province?tm=" + tm,
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.province_arry = data.data;
                                }
                            }
                        })
                    },
                    city: function () {
                        var _this = this;
                        var id = $("#provinceId option:selected").val()
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/index?tm=" + tm,
                            data: {
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.city_arry = data.data;
                                    _this.area_arry = [];
                                }
                            }
                        })
                    },
                    area: function () {
                        var _this = this;
                        var id = $("#cityId option:selected").val()
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/index?tm=" + tm,
                            data: {
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.area_arry = data.data;
                                }
                            }
                        })
                    },
                    businessType: function () {
                        var _this = this;
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/goods/add?tm=" + tm,
                            data: {
                                token: token
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.goods_arry = data.data;
                                }
                            }
                        })
                    },
                    releaseSubmit: function () {
                        var category_id = $("#typeId").val();
                        var title = $("#titleId").val();
                        var contacts = $("#nameId").val();
                        var mobile = $("#phoneId").val();
                        var province = $("#provinceId").val();
                        var city = $("#cityId").val();
                        var area = $("#areaId").val();
                        var buy_num = $("#numId").val();
                        var description = $("#describeId").val();
                        if (category_id == 0) {
                            YDUI.dialog.alert('请选择商机类型!');
                            return false;
                        }
                        if (title == "") {
                            YDUI.dialog.alert('请填写商机标题!');
                            return false;
                        }
                        if (contacts == "") {
                            YDUI.dialog.alert('请填写联系人!');
                            return false;
                        }
                        if (mobile == "") {
                            YDUI.dialog.alert('请填写联系电话!');
                            return false;
                        }
                        if (!rules_phone.exec(mobile)) {
                            YDUI.dialog.alert("联系电话格式错误!");
                            return false;
                        }
                        if (province == 0) {
                            YDUI.dialog.alert('请选择省!');
                            return false;
                        }
                        if (city == 0) {
                            YDUI.dialog.alert('请选择市!');
                            return false;
                        }
                        if (area == 0) {
                            YDUI.dialog.alert('请选择区!');
                            return false;
                        }
                        if (buy_num == "") {
                            YDUI.dialog.alert('请填写采购量!');
                            return false;
                        }
                        if (description == "") {
                            YDUI.dialog.alert('请填写商机描述!');
                            return false;
                        }
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/goods/add?token=" + token + "&tm=" + tm,
                            data: {
                                "category_id": category_id,
                                "title": title,
                                "contacts": contacts,
                                "mobile": mobile,
                                "province": province,
                                "city": city,
                                "area": area,
                                "buy_num": buy_num,
                                "description": description
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    YDUI.dialog.toast(data.msg, 'success', 2000, function () {
                                        window.location.href="vip.html"
                                    });
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    }
                }
            })
        }
    </script>
</body>

</html>